/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.reduce.klsh.kmeaning;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.WritableComparable;

/**
 *
 * @author nastya
 */
public class DictionaryCoordinatePair implements WritableComparable<DictionaryCoordinatePair> {

    private String dictionaryNum;
    private String coordinateNum;
    private Double distance;

    public byte[] getCoordinateNumBytes() {
        return Bytes.toBytes(coordinateNum);
    }

    public byte[] getDictionaryNumBytes() {
        return Bytes.toBytes(dictionaryNum);
    }

    public byte[] getDistanceBytes() {
        return Bytes.toBytes(distance);
    }

    public DictionaryCoordinatePair(String dictionaryNum, String coordinateNum, Double distance) {
        this.dictionaryNum = dictionaryNum;
        this.coordinateNum = coordinateNum;
        this.distance = distance;
    }

    public DictionaryCoordinatePair() {
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        dictionaryNum = in.readUTF();
        coordinateNum = in.readUTF();
        distance = in.readDouble();
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(dictionaryNum);
        out.writeUTF(coordinateNum);
        out.writeDouble(distance);
    }

    @Override
    public int compareTo(DictionaryCoordinatePair t) {
        if (t == null) {
            return 1;
        }
        if (t.dictionaryNum.compareTo(dictionaryNum) == 0) {
            return t.coordinateNum.compareTo(coordinateNum);
        }

        return t.dictionaryNum.compareTo(dictionaryNum);
    }
}
